package com.icart.controller;

import com.icart.restful.ImageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Controller;
import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.util.concurrent.ListenableFutureCallback;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * Created by kim on 17/12/20.
 */
@RequestMapping(value = "common")
@Controller
public class CommonController {


    @Autowired
    ImageService imageService;

    @RequestMapping("index")
    @ResponseBody
    public String index(){
        return "common-index22666666";
    }

    @RequestMapping("image")
    @ResponseBody
    public ResponseEntity<byte[]> image( String filename){
        return  imageService.get(filename);
    }

    @RequestMapping("imageasync")
    @ResponseBody
    public ResponseEntity<byte[]> imageAsync( String filename) throws ExecutionException, InterruptedException {
        ListenableFuture<ResponseEntity<byte[]>> listenableFuture= imageService.getAsync(filename);
        return listenableFuture.get();
    }
}
